package com.glorysoft.xztpda.ui.orcomment

import com.glorysoft.xztpda.base.BaseViewModel
import com.glorysoft.xztpda.entity.OrEntity
import com.glorysoft.xztpda.model.LotRepository
import com.google.gson.JsonObject

/**
 * FileName: OrCommentViewModel
 * Author: XJH
 * Date: 2022/4/20 11:44
 * Description:
 * History:
 */
class OrCommentViewModel : BaseViewModel() {
    private val repository: LotRepository = LotRepository()
    var orData : OrEntity? = null
    val bilityList = arrayListOf("人","机","料","法","环")

    fun getData(or : String){
        val map = JsonObject()
        map.addProperty("ACTIONTYPE","QREXCEPTIONQUERY")
        map.addProperty("QRDOC",or)
        launchOnlyResult({
            orData = repository.getORData(map)
            defUI.callObserve.call()
        })
    }

    fun submit(or: String, comment: String, cor: String, bibily: String,res : String,res2 : String) {
        val map = JsonObject()
        map.addProperty("ACTIONTYPE","QREXCEPTION")
        map.addProperty("QRDOC",or)
        map.addProperty("HOLDCODE",orData?.HOLDCODE)
        map.addProperty("HOLDREASON",orData?.HOLDREASON)
        map.addProperty("LOTID",orData?.LOTID)
        map.addProperty("HOLDCOMMENTS",comment)
        map.addProperty("RESPONSIBILITY",bibily)
        map.addProperty("CORRECTIVE",cor)
        map.addProperty("RESPTE",res)
        map.addProperty("RESPLEADER",res2)
        launchOnlyResult({
            repository.submitOr(map)
            defUI.startActivity.call()
        })
    }

}